// 录入比例设置控制器
define('clientProportionController', ['angular'], function (angular) {
    var module = angular.module('controllers');
    module.controller('clientProportionController', ['$scope','$rootScope','$filter','userServers',function ($scope,$rootScope,$filter,userServers) {
        $scope.proportionSearch=function(){
            var companyid;
            if(!$scope.company){
                companyid=$rootScope.user.company;
            }else{
                companyid=$scope.company;
            }
            if(!$rootScope.userList){
                userServers.userList().then(function (data) {
                    $rootScope.userList=data;
                    $scope.userList=$filter("arrChoosenFilter")(angular.copy($rootScope.userList),{'company':companyid});
                });
            }
            $scope.userList=$filter("arrChoosenFilter")(angular.copy($rootScope.userList),{'company':companyid});
        };
        $scope.proportionSearch();
        $scope.editProportion=function(){
            var percent=0;
            for (var i = 0; i < $scope.userList.length; i++) {
                percent+=parseInt($scope.userList[i].input_proportion);
                delete $scope.userList[i].company_name;
            }
            if(percent!=100){
                alert("您输入的值相加不为100");
            }else{
                userServers.setUserList($scope.userList).then(function (data) {
                    if(data){
                        alert("修改成功");
                    }else{
                        alert("修改失败");
                    }
                });
            }
        };
    }]);
});